<template>
  <!-- 评论页面的单元评论区分装 -->
  <div>
    <div class="bgs">
      <div class="boxs">
        <img :src="url + v.user.head_img" />
        <div class="centers">
          <p>{{ v.user.nickname }}</p>
          <span>{{ v.create_date | relativeformat }}</span>
        </div>
        <span @click="tocomment(v)" class="butts">回复</span><br /><br />
      </div>
      <div class="contents">{{ v.content }}</div>
      <mycom v-if="v.parent" :v="v.parent" @send="tocomment(v)"></mycom>
    </div>
  </div>
</template>

<script>
import { relativeformat } from "@/utils/myfilters.js";
import axios from "@/utils/myaxios";
export default {
  //如果有使用组件递归必须为组件添加name属性,这个属性值就可以当成组件来使用
  name: "mycom",
  props: ["v"],
  data() {
    return {
      url: axios.defaults.baseURL,
    };
  },
  filters: {
    relativeformat,
  },
  methods: {
    //子组件中的回复按钮事件
    tocomment(v) {
      this.$emit("send", v);
    },
  },
};
</script>

<style lang="less" scoped>
.bgs {
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
}
.boxs {
  // padding: 10px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #888;
  > img {
    display: block;
    width: 50/360 * 100vw * 0.7;
    height: 50/360 * 100vw * 0.7;
    border-radius: 50%;
    padding: 0 10px;
  }
  > .centers {
    flex: 1;
    padding: 0 0 10px;
    > p {
      line-height: 30px;
      font-size: 14px;
    }
  }
  .butts {
    height: 20px;
    background-color: #eee;
    font-size: 13px;
    border-radius: 30px;
    line-height: 20px;
    padding: 2px 15px;
  }
}
.contents {
  text-indent: 10px;
  font-size: 14px;
}
</style>